package com.tian.consumer;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import com.tian.message.PhoneMessage;
import com.tian.service.SendSmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年05月14日 22:22
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 * <p>
 * 异步发送短信
 */
@Slf4j
@Component
public class SendMsgConsumer {

    @Resource
    private SendSmsService sendSmsService;

    @RabbitListener(queues = {"${rabbitmq.phon.message.queue.name}"})
    public void onMessage(PhoneMessage phoneMessage) throws Exception {
        try {
            Map<String, String> params = new HashMap<>();
            sendSmsService.sendSms(phoneMessage.getPhone(), phoneMessage.getContent(), phoneMessage.getParams());
        } catch (Exception e) {
            log.error("消费者处理失败：短信发送 ", e);
        }
    }
}


